<?php
/**
 * class of eventsmq handler
 */
class EventsMQ_Handler extends EventsMQ
{
	public function __construct ()
	{
		parent::__construct();
		$this->_wait_time = 3;
		$this->_muser     = new MUser;
	}

	public function handle_event ($max_messages,$group = 'default') 
	{
		$n = 0;
		while ($n < $max_messages)
		{
			$v = $this->get($group);
			if (FALSE === $v)
			{
				sleep($this->_wait_time);
			}
			else
			{
				++$n;
				$this->record_event ($v);
			}

		} // while
	}

	protected function record_event ($event)
	{
		if (is_array($event) && !empty($event))
		{
			if ($event['type'] == 'resize_img')
				Upimage::handle($event);
			else if ($event)
				MUser::handle($event);
		}
	}
}
